package com.org.utils.currency;

import java.text.DecimalFormat;

/**
 * 货币类型的处理
 * 
 * @author 
 * 
 */
public class CurrencyUtils {

	/**
	 * 货币金额取小数点后两位(eg:20.01)-针对Double/double类型值
	 */
	public static Double formatCurrency(Double unFormatCurrency) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		String formatCurrencyStr = df.format(unFormatCurrency==null?0.0:unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency;
	}
	
	/**
	 * 货币金额取小数点后两位(eg:20.01)-针对String类型值
	 */
	public static Double formatCurrency(String unFormatCurrencyStr) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		Double unFormatCurrency = Double.valueOf(unFormatCurrencyStr==null?"0.0":unFormatCurrencyStr);
		String formatCurrencyStr = df.format(unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency;
	}
	public static Double formatCurrency(Object unFormatCurrencyStr) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		Double unFormatCurrency = Double.valueOf(unFormatCurrencyStr==null?"0.0":unFormatCurrencyStr.toString());
		String formatCurrencyStr = df.format(unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency;
	}
	/**
	 * 货币金额取小数点后两位(eg:20.01)-针对Double类型值转换String
	 * @param unFormatCurrency
	 * @return
	 */
	public static String formatCurrency2Str(Double unFormatCurrency) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		String formatCurrencyStr = df.format(unFormatCurrency==null?0.0:unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency.toString();
	}
	
	/**
	 * 货币金额取小数点后两位(eg:20.01)-针对String类型值转换String
	 */
	public static String formatCurrency2Str(String unFormatCurrencyStr) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		Double unFormatCurrency = Double.valueOf(unFormatCurrencyStr==null?"0.0":unFormatCurrencyStr);
		String formatCurrencyStr = df.format(unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency.toString();
	}
	public static String formatCurrency2Str(Object unFormatCurrencyStr) {
		// 定义返回
		Double formatCurrency;
		// 格式货币到小数点后两位
		DecimalFormat df = new DecimalFormat("#.##");
		Double unFormatCurrency = Double.valueOf(unFormatCurrencyStr==null?"0.0":unFormatCurrencyStr.toString());
		String formatCurrencyStr = df.format(unFormatCurrency);
		formatCurrency = new Double(formatCurrencyStr);
		// 返回
		return formatCurrency.toString();
	}
	
	
}
